package com.xhwl.logistics.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.logistics.bo.VehicleCardBO;
import com.xhwl.logistics.bo.input.PageBO;
import com.xhwl.logistics.bo.input.QueryVehicleCardBO;
import com.xhwl.logistics.converter.ToPageBO;
import com.xhwl.logistics.converter.ToPageVO;
import com.xhwl.logistics.converter.mapstruct.VehicleCardConverter;
import com.xhwl.logistics.dto.query.VehicleCardDTO;
import com.xhwl.logistics.service.business.VehicleCardBusinessService;
import com.xhwl.logistics.vo.PageVO;
import com.xhwl.logistics.vo.VehicleCardVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

//@RestController
public class VehicleCardController {

    @Autowired
    private VehicleCardConverter vehicleCardConverter;

    @Autowired
    private VehicleCardBusinessService vehicleCardBusinessService;

    @Autowired
    private ToPageBO toPageBO;

    @Autowired
    private ToPageVO toPageVO;

    @PostMapping("/charge-rule/list")
    public ResultJson<List<VehicleCardVO>> query(@RequestBody VehicleCardDTO vehicleCardDTO) {
        QueryVehicleCardBO queryVehicleCardBO = vehicleCardConverter.vehicleCardDTO2QueryVehicleCardBO(vehicleCardDTO);

        List<VehicleCardBO> vehicleCardBOList = vehicleCardBusinessService.queryCards(queryVehicleCardBO);

        List<VehicleCardVO> vehicleCardVOList = vehicleCardConverter.vehicleCardBOList2VehicleCardVOList(vehicleCardBOList);
        return ResultJson.successWithResult(vehicleCardVOList);
    }

    @PostMapping("/charge-rule/page")
    public ResultJson<PageVO<VehicleCardVO>> card(@RequestBody VehicleCardDTO vehicleCardDTO) {
        QueryVehicleCardBO queryVehicleCardBO = vehicleCardConverter.vehicleCardDTO2QueryVehicleCardBO(vehicleCardDTO);
        PageBO pageBO = toPageBO.toPageBOForCard(vehicleCardDTO);

        IPage<VehicleCardBO> vehicleCardBOIPage = vehicleCardBusinessService.queryCards(queryVehicleCardBO, pageBO);

        List<VehicleCardVO> vehicleCardVOList = vehicleCardConverter.vehicleCardBOList2VehicleCardVOList(vehicleCardBOIPage.getRecords());
        return ResultJson.successWithResult(toPageVO.toPageVO(vehicleCardBOIPage, vehicleCardVOList));
    }

}
